package sg.edu.nus.iss.vmcs.interfaces;

import java.awt.Frame;

import sg.edu.nus.iss.vmcs.customer.AwtCustomerPanel;
import sg.edu.nus.iss.vmcs.customer.CustomerUI;
import sg.edu.nus.iss.vmcs.machinery.MachineryController;
import sg.edu.nus.iss.vmcs.machinery.MachineryInterface;
import sg.edu.nus.iss.vmcs.machinery.AwtMachinerySimulatorPanel;
import sg.edu.nus.iss.vmcs.maintenance.MaintenanceController;
import sg.edu.nus.iss.vmcs.maintenance.AwtMaintenancePanel;
import sg.edu.nus.iss.vmcs.maintenance.MaintenanceUI;
import sg.edu.nus.iss.vmcs.system.MainController;
import sg.edu.nus.iss.vmcs.system.SimulationController;
import sg.edu.nus.iss.vmcs.system.AwtSimulatorControlPanel;
import sg.edu.nus.iss.vmcs.system.TransactionController;
import sg.edu.nus.iss.vmcs.system.VMCSControlUI;

public class SimulationGUIFactory extends InterfaceFactory {
	private Frame frame = null;

	private static InterfaceFactory instance = null;
	public static InterfaceFactory getInstance() {
		if (instance == null) {
			instance = new SimulationGUIFactory();
		}
		return instance;
	}
	private SimulationGUIFactory() {
		System.out.println("<<Abstract Factory>> An instance of class '" +getClass().getName()+ "' is being constructed.");
	}
	
	@Override
	public VMCSControlUI createVMCSControlUI(SimulationController controller) {
		AwtSimulatorControlPanel controlUI = new AwtSimulatorControlPanel(controller);
		printClassInstanceCreated(controlUI.getClass());
		frame = controlUI;
		return controlUI;
	}

	@Override
	public MachineryInterface createMachineryInterface(MachineryController controller) {
		MachineryInterface mi = new AwtMachinerySimulatorPanel(frame, controller);
		printClassInstanceCreated(mi.getClass());
		return mi;
	}

	@Override
	public MaintenanceUI createMaintenanceUI(MaintenanceController controller) {
		MaintenanceUI mui = new AwtMaintenancePanel(frame, controller);
		printClassInstanceCreated(mui.getClass());
		return mui;
	}

	@Override
	public CustomerUI createCustomerUI(TransactionController tc,
			MainController mc) {
		CustomerUI cui = new AwtCustomerPanel(frame, tc, mc);
		printClassInstanceCreated(cui.getClass());
		return cui;
	}
	
	private void printClassInstanceCreated(@SuppressWarnings("rawtypes") Class cls) {
		System.out.println("<<Abstract Factory>> An instance of class '"+cls.getName()+"' has been created.");
	}
}
